#include <bits/stdc++.h>
using namespace std;
int a[300000], b[300000];
int a0[300000], a1[300000];
int cnt0, cnt1;
int main() {
    //freopen("colour.in", "r", stdin);
    //freopen("colour.out", "w", stdout);
    int T, n;
    int sum = 0;
    cin >> T;
    for (int t = 0; t < T; t++) {
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (a[j] == a[i]) {
                    b[i] = b[j];
                    for (int k = j + 1; k < i; k++) {
                        b[k] = 1 - b[j];
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if(b[i] == 0) {
                a0[cnt0] = a[i];
                cnt0++;
            }
            else{
                a1[cnt1] = a[i];
                cnt1++;
            }
        }
        for (int i = 1; i < cnt0; i++) {
            if(a0[i] == a0[i-1]) {
                sum += a0[i];
            }
        }
        for (int i = 1; i < cnt1; i++) {
            if(a1[i] == a1[i-1]) {
                sum += a1[i];
            }
        }
        cout << sum << endl;
        sum = 0;
        cnt0 = 0;
        cnt1 = 0;
    }
    return 0;
}
